/*获取url请求参数的相关方法*/
var user_config = {
    ucellphone:'',
    uname: '',
    servParm:(function(){
        var url = window.location.href;
        var parm = url.substr(url.lastIndexOf('/')+1);
        return parm;
    })(),
    servTypes:{'pb':'嗖嗖顺购','qe':'嗖嗖排队','bw':'嗖嗖顺捎','dh':'嗖嗖顺驾','hk':'嗖嗖家政','rp':'嗖嗖维修','st':'嗖嗖接送','hw':'其他'},
    typeSelect:undefined,
    isOut:true,//跑腿类型选择菜单状态
    //inital_right:undefined,
    opt:{//时间选择插件初始配置
        preset:'datetime',//日期
        theme:'sense-ui',//皮肤样式
        display:'top',//显示方式
        lang:'zh',
        mode:'scroller',//日期选择模式
        dateFormat:'yy-mm-dd', // 日期格式
        setText:'确定',
        cancelText:'取消',
        showNow:true,
        nowText:'今天',
        dateOrder:'yymmdd', //面板中日期排列格式
        startYear:(new Date()).getFullYear(),
        endYear:2050 //结束年份
    },
	intal_lng:0,
	intal_lat:0
}
/*显示弹框提示*/
function showMessage(message){
    var content = {};
    content.title = '';
    content.text = message;
    content.animation = 'slide-from-bottom';
    content.timer = 1000;
    content.showConfirmButton = false;
    swal(content);
}
/**
 * service form
 * */
/*页面初始化时已选择跑腿类型*/
if(user_config.servTypes[user_config.servParm] != undefined){
    /*加载跑腿类型输入项*/
    $('#serv-type').val(user_config.servTypes[user_config.servParm]).attr('data-type',user_config.servParm);;
    /*根据url参数选择跑腿类型子菜单*/
    $('.sub_service .list-group-item[id='+ user_config.servParm + ']').addClass('active');
    user_config.typeSelect = user_config.servParm;
}
/*跑腿类型子菜单展示与隐藏*/
var serviceSel = $(".serv-sel").hammer();
serviceSel.on('tap',function(){
	if(user_config.isOut){
		user_config.isOut = false;
		$('.sub_service').show('fast',function(){
			$('.sub_service>ul').animate({right:0},'normal','linear');
		});
    }
    /*选择跑腿类型*/
    var type = $('.sub_service .list-group-item').hammer();
    type.on('tap',function(e){
        $(this).addClass("active").siblings().removeClass('active');
        $('#serv-type').val($(this).html()).attr('data-type',$(this).attr('id'));
        user_config.typeSelect = $(this).attr('id');
    });
	var subServiceMenu = $('.sub_service').hammer();
	subServiceMenu.on('tap',function(){
		if(!user_config.isOut){
			user_config.isOut = true;
			$('.sub_service>ul').animate({right:'-40%'},'normal','linear',function(){
				$('.sub_service').css('display','none');
			});
		}
	});
});

/*时间插件调用*/
var servDataTime = $('.dateTime').hammer();
servDataTime.on('tap',function(){
    $('#serv-datetime').mobiscroll(user_config.opt);
});
/*键盘和语音按钮切换*/
var keyword = $('.service-form .btn-keyword').hammer();
keyword.on('tap',function(){
    var btnShown = $('.service-form .btn-keyword b:visible');
    var btnShownId = btnShown.attr('id');
    var num = btnShownId.substring(btnShownId.indexOf('-')+1);
    $('.service-form .description').find('#desc-'+num).show().siblings().hide();
    $('.service-form .btn-keyword b:hidden').show().siblings().hide();
});
/*server form 表单输入项验证*/
function checkServForm(){
    if (($('#serv-type').val() == null || $('#serv-type').val() == '')) {
        showMessage('请选择跑腿类型');
        return false;
    }
    if ($('#serv-theme').val() == null || $('#serv-theme').val() == '') {
        showMessage('请填写跑腿主题');
        return false;
    }
    if ($('#serv-datetime').val() == null || $('#serv-datetime').val() == '') {
        showMessage('请选择服务时间');
        return false;
    }
    if ($('#serv-cost').val() == null || $('#serv-cost').val() == '') {
        showMessage('请填写跑腿费用');
        return false;
    }
    if ($('#serv-cost').val() < 5) {
        showMessage('跑腿费用不得低于5元');
        return false;
    }
    return true;
}
/*跳转到确认支付表单*/
var toPayStep = $('.service-form .toPayStep').hammer();
toPayStep.on('click',function(){
    //if(checkServForm()){
        $(this).hide();
        orderFormInit(user_config.typeSelect);
        $('.pay-order').show().animate({right:0},'normal','linear');
    //};
});
/**
 * pay-order
 */
/*根据跑腿类型创建不同的确认支付表单*/
function orderFormInit(type){
    var html;
    switch(type){
        case 'pb'://嗖嗖顺购
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
                +       '<div class="form-group" id="detail-start">'
                +           '<label for="detail-start-place" class="col-xs-3 input-label">交货地点:</label>'
                +           '<div class="col-xs-9 input-cont">'
                +               '<input class="auth-input" id="detail-start-place" type="text" name="destplace" readonly/>'
                +           '</div>'
                +       '</div>'
                +       '<div class="form-group" hidden>'
                +           '<label for="detail-start-longitude" class="col-xs-3 input-label">交货地点经度:</label>'
                +           '<div class="col-xs-9 input-cont">'
                +               '<input class="auth-input" id="detail-start-longitude" type="text" name="dest_longitude" readonly/>'
                +           '</div>'
                +       '</div>'
                +       '<div class="form-group" hidden>'
                +           '<label for="detail-start-latitude" class="col-xs-3 input-label">交货地点纬度:</label>'
                +           '<div class="col-xs-9 input-cont">'
                +               '<input class="auth-input" id="detail-start-latitude" type="text" name="dest_latitude" readonly/>'
                +           '</div>'
                +       '</div>'
                +       '<div class="form-group">'
                +           '<span class="col-xs-12 text-right distance">交货地点距我约<span>未知</span></span>'
                +       '</div>'
                +       '<div class="form-group">'
                +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
                +           '<div class="col-xs-9 input-cont">'
                +               '<input class="auth-input" id="detail-username" type="text" name="recipient_name" placeholder="微信昵称"/>'
                +           '</div>'
                +       '</div>'
                +       '<div class="form-group">'
                +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
                +           '<div class="col-xs-9 input-cont">'
                +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="recipient_phone"/>'
                +           '</div>'
                +       '</div>'
                +       '<div class="form-group last-form-group">'
                +           '<span>嗖嗖跑腿详情</span>'
                +           '<div class="order-detail">'
                +               '<table>'
                +                   '<tr hidden>'
                +                       '<td>跑腿类型:</td>'
                +                       '<td><input type="text" name="type" id="detail-type" value="pb" readonly/></td>'
                +                   '</tr>'
                +                   '<tr>'
                +                       '<td>跑腿主题:</td>'
                +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
                +                   '</tr>'
                +                   '<tr>'
                +                       '<td>交货时间:</td>'
                +                       '<td><input type="text" name="goods_latest_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
                +                   '</tr>'
                +                   '<tr>'
                +                       '<td>跑腿费用:</td>'
                +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
                +                   '</tr>'
                +                   '<tr>'
                +                       '<td valign="top">重要说明:</td>'
                +                       '<td><textarea type="text" name="goods_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
                +                   '</tr>'
                +               '</table>'
                +           '</div>'
                +         '</div>'
                +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
                +   '</form>';
            break;
        case 'qe'://嗖嗖排队
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">排队地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="queue_place" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">排队地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="queue_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">排队地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="queue_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">排队地点距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="queue_username" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label ">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="queue_phone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="qe" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>排队时间:</td>'
            +                       '<td><input type="text" name="queue_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="queue_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
        case 'bw'://嗖嗖顺捎
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">交货地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="location_getgoods" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">交货地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="location_getgoods_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">交货地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="location_getgoods_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" id="detail-end">'
            +           '<label for="detail-end-place" class="col-xs-3 input-label">收货地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-place" type="text" name="location_deliver" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-end-longitude" class="col-xs-3 input-label">收货地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-longitude" type="text" name="location_deliver_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-end-latitude" class="col-xs-3 input-label">收货地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-latitude" type="text" name="location_deliver_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">交货地点距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="goods_to_name" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="goods_to_phone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="bw" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>取货时间:</td>'
            +                       '<td><input type="text" name="get_goods_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="goods_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
        case 'dh'://嗖嗖顺驾
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">出发地:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="startplace" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">出发地经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="start_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">出发地纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="start_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" id="detail-end">'
            +           '<label for="detail-end-place" class="col-xs-3 input-label">目的地:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-place" type="text" name="destplace" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-end-longitude" class="col-xs-3 input-label">目的地经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-longitude" type="text" name="dest_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-end-latitude" class="col-xs-3 input-label">目的地纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-latitude" type="text" name="dest_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">顺驾出发地距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="contact_name" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="cellphone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="bw" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>代驾时间:</td>'
            +                       '<td><input type="text" name="drive_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
        case 'hk'://嗖嗖家政
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">家政地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="hk_place" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">家政地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="hk_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">家政地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="hk_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">家政地点距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="hk_username" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="hk_phone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="bw" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>服务时间:</td>'
            +                       '<td><input type="text" name="hk_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="hk_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
        case 'rp'://嗖嗖维修
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">维修地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="rp_place" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">维修地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="rp_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">维修地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="rp_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">维修地点距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="rp_name" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="rp_phone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="bw" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>维修时间:</td>'
            +                       '<td><input type="text" name="rp_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="rp_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
        case 'st'://嗖嗖接送
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">见面地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="st_place" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">见面地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="st_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">见面地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="st_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" id="detail-end">'
            +           '<label for="detail-end-place" class="col-xs-3 input-label">目的地:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-place" type="text" name="st_destplace" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-end-longitude" class="col-xs-3 input-label">目的地经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-longitude" type="text" name="st_destlongitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-end-latitude" class="col-xs-3 input-label">目的地纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-end-latitude" type="text" name="st_destlatitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">见面地距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="st_username" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="st_phone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="bw" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>见面时间:</td>'
            +                       '<td><input type="text" name="st_time" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="st_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
        case 'hw'://其他
            html = '<form action="#" method="post" class="form-horizontal order-form" onsubmit="return checkOrderForm()">'
            +       '<div class="form-group" id="detail-start">'
            +           '<label for="detail-start-place" class="col-xs-3 input-label">服务地点:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-place" type="text" name="hw_place" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-longitude" class="col-xs-3 input-label">服务地点经度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-longitude" type="text" name="hw_longitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group" hidden>'
            +           '<label for="detail-start-latitude" class="col-xs-3 input-label">服务地点纬度:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-start-latitude" type="text" name="hw_latitude" readonly/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<span class="col-xs-12 text-right distance">服务地点距我约<span>未知</span></span>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-username" class="col-xs-3 input-label">联系人:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-username" type="text" name="hw_name" placeholder="微信昵称"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group">'
            +           '<label for="detail-phone" class="col-xs-3 input-label">联系电话:</label>'
            +           '<div class="col-xs-9 input-cont">'
            +               '<input class="auth-input" id="detail-phone" type="tel" maxlength="11" name="hw_cellphone"/>'
            +           '</div>'
            +       '</div>'
            +       '<div class="form-group last-form-group">'
            +           '<span>嗖嗖跑腿详情</span>'
            +           '<div class="order-detail">'
            +               '<table>'
            +                   '<tr hidden>'
            +                       '<td>跑腿类型:</td>'
            +                       '<td><input type="text" name="type" id="detail-type" value="bw" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿主题:</td>'
            +                       '<td><input type="text" name="theme" id="detail-theme" value="'+ $('#serv-theme').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>服务时间:</td>'
            +                       '<td><input type="text" name="hw_starttime" id="detail-time" value="' + $('#serv-datetime').val() + '" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td>跑腿费用:</td>'
            +                       '<td><input type="text" name="serve_price" id="detail-price" value="' + $('#serv-cost').val() + '元" readonly/></td>'
            +                   '</tr>'
            +                   '<tr>'
            +                       '<td valign="top">重要说明:</td>'
            +                       '<td><textarea type="text" name="hw_description" id="detail-description" readonly>' + $('#desc-1').val() + '</textarea></td>'
            +                   '</tr>'
            +               '</table>'
            +           '</div>'
            +         '</div>'
            +         '<button type="submit" class="btn btn-block btn-lg navbar-fixed-bottom theme-color pay-confirm">确认支付</button>'
            +   '</form>';
            break;
    }
    $('.pay-order').append($(html));
    //加载用户名称
	if(user_config.uname){$('#detail-username').val(user_config.uname)}
    //加载联系电话
	if(user_config.ucellphone)($('#detail-phone').val(user_config.ucellphone));
	/**
	* 获取位置
	*/
	var startPlace = $('#detail-start').hammer();
	startPlace.on('tap',function(){
        mapShow(true);
        console.log('--------获取开始位置--------');
        console.log('初始地图中心点:' + user_config.intal_lng  + "," + user_config.intal_lat);
		var ulongitude = $('#detail-start-longitude').val() || user_config.intal_lng;
		var ulatitude = $('#detail-start-latitude').val() || user_config.intal_lat;
		//地图初始化
		initMap($(this).attr('id'),new BMap.Point(ulongitude, ulatitude));

	});
	var endPlace = $('#detail-end').hammer();
	endPlace.on('tap',function(){
		mapShow(true);
		console.log('-------获取结束位置---------');
		console.log('初始地图中心点:' + user_config.intal_lng  + "," + user_config.intal_lat);
		var ulongitude = $('#detail-end-longitude').val() || user_config.intal_lng;
		var ulatitude = $('#detail-end-latitude').val() || user_config.intal_lat;
		//地图初始化
		initMap($(this).attr('id'),new BMap.Point(ulongitude, ulatitude));
	});
}

function mapShow(flag){
	if(flag){
		$('.map-page').css('display','block').animate({right:0},'normal','linear',function(){$('.pay-confirm').hide();});		
	}else{
		$('.map-page').animate({right:'-100%'},'normal','linear',function(){$('.map-page').css('display','none');$('.pay-confirm').show();});
	}
}

function initMap($tid,point) {
    //加载当前坐标城市
    initCity(point);
    //map自适应宽高
    var mapW = $('.map-page').width(), mapH = $('.map-page').height()/2;
    $('#map').css({'width': mapW + 'px', 'height': mapH + 'px'});	
	var map = new BMap.Map("map");//创建地图实例
    map.centerAndZoom(point,15);//初始化地图，设置中心点坐标和地图级别
    //给地图中心点加上一个水滴图标
    var pointIcon = $('<div class="center-point"></div>');
    $('#map').append(pointIcon);
    var center_top = mapH/2 - $('#map .center-point').height() + 'px';
    var center_left = mapW/2 - $('#map .center-point').width()/2 + 'px';
    pointIcon.css({'top':center_top,'left':center_left});
    //根据中心点搜索周边房屋列表
    getListByPoint($tid,map,point);
    //地图拖拽
    map.enableDragging();
    map.addEventListener("dragend", function(){
        var center = map.getCenter();
        console.log("地图中心点变更为：" + center.lng + ", " + center.lat);
        getListByPoint($tid,map,new BMap.Point(center.lng, center.lat));
    });
    //模糊查询
    var ac = new BMap.Autocomplete({"input":"map-keyword","location":map});
    ac.addEventListener("onconfirm", function(e) {
        var address = $('#map-keyword').val();
        var city = $('#cityName').text();
        var myGeo = new BMap.Geocoder();
        // 将地址解析结果显示在地图上,并调整地图视野
        myGeo.getPoint(address,function(point){
            if(point){
				console.log(address);
				console.log(point)
                //map.centerAndZoom(point,15);
				map.panTo(point);
				getListByPoint($tid,map,point);
            }
        },city);
    });
}

var mapBack = $('.search-box .back').hammer();
mapBack.on('tap',function(){mapShow(false)});

/**
 * 地图相关方法
 * */
function initCity(point){
    var gc = new BMap.Geocoder();
    gc.getLocation(point,function(rs){
        $('#cityName').text(rs.addressComponents.city);
    })
}
function getListByPoint($tid,map,point){
    var options = {
        onSearchComplete: function(results){
            if (local.getStatus() == BMAP_STATUS_SUCCESS){
                addLocList($tid,map,$('#mp-location'),results);
                console.log('results:');
				console.log(results);
            }
        }
    };
    var local = new BMap.LocalSearch(map,options);
    local.searchNearby('房屋',point,500);
}
function addLocList($tid,map,$ul,rsList){
    $ul.children().remove();
    var liList = '';
	console.log(rsList);
    for (var i = 0; i < rsList.getCurrentNumPois(); i ++){
        liList += '<li class="list-group-item" data-point-lng="' + rsList.getPoi(i).point.lng + '" data-point-lat="' + rsList.getPoi(i).point.lat + '">'+ rsList.getPoi(i).address + '</li>';
    }
    $ul.append(liList);
    var listTap = $ul.children().hammer();
    listTap.on('tap',function(){
        var address = $(this).text();
        var lng = $(this).attr('data-point-lng');
        var lat = $(this).attr('data-point-lat');
        console.log(address + '[' + lng + ',' + lat + ']');
		$('#'+$tid+'-place').val($(this).text());
		$('#'+$tid+'-longitude').val(lng);
		$('#'+$tid+'-latitude').val(lat);
		//更改距离
		$tid === 'detail-start' && changeDistance(map,new BMap.Point(lng, lat));
		//map.panTo(new BMap.Point(lng,lat));
		mapShow(false);
		
		console.log('--------start------------');
		console.log($('#detail-start-longitude').val());
		console.log($('#detail-start-latitude').val());
		console.log('--------end------------');
		console.log($('#detail-end-longitude').val());
		console.log($('#detail-end-latitude').val());
	});
}
function changeDistance(map,s_point){
	var distance = map.getDistance(new BMap.Point(user_config.intal_lng,user_config.intal_lat),s_point);
	distance = distance>=1000 ? ((distance/1000).toFixed(2)+'km') : (Math.ceil(distance)+'m');
	$('.order-form .distance>span').text(distance);
	console.log(distance);
}


/* 确认支付表单输入项验证*/
function checkOrderForm(){
    var type = user_config.typeSelect;
    switch(type){
        case 'pb'://嗖嗖顺购
            if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择交货地点');
                return false;
            }
			if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('交货地点经度获取失败');
				return false;
            }
			if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
				showMessage('交货地点纬度获取失败');
				return false;
			}
            break;
        case 'qe'://嗖嗖排队
            if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择排队地点');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('排队地点经度获取失败');
                return false;
            }
            if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('排队地点纬度获取失败');
                return false;
            }
            break;
        case 'bw'://嗖嗖顺捎
            if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择交货地点:');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('交货地点经度获取失败');
                return false;
            }
            if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('交货地点纬度获取失败');
                return false;
            }
            if ($('#detail-end-place').val() == null || $('#detail-end-place').val() == '') {
                showMessage('请选择收货地点:');
                return false;
            }
            if ($('#detail-end-longitude').val() == null || $('#detail-end-longitude').val() == '') {
                showMessage('收货地点经度获取失败');
                return false;
            }
            if ($('#detail-end-latitude').val() == null || $('#detail-end-latitude').val() == '') {
                showMessage('收货地点纬度获取失败');
                return false;
            }
            break;
        case 'dh'://嗖嗖顺驾
			if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择出发地:');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('出发地经度获取失败');
                return false;
            }
            if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('出发地纬度获取失败');
                return false;
            }
            if ($('#detail-end-place').val() == null || $('#detail-end-place').val() == '') {
                showMessage('请选择目的地:');
                return false;
            }
            if ($('#detail-end-longitude').val() == null || $('#detail-end-longitude').val() == '') {
                showMessage('目的地经度获取失败');
                return false;
            }
            if ($('#detail-end-latitude').val() == null || $('#detail-end-latitude').val() == '') {
                showMessage('目的地纬度获取失败');
                return false;
            }
            break;
        case 'hk'://嗖嗖家政
            if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择家政地点');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('家政地点经度获取失败');
                return false;
            }
            if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('家政地点纬度获取失败');
                return false;
            }
			break;
        case 'rp'://嗖嗖维修
            if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择维修地点');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('维修地点经度获取失败');
                return false;
            }
            if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('维修地点纬度获取失败');
                return false;
            }
			break;
        case 'st'://嗖嗖接送
			if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择见面地点:');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('见面地点经度获取失败');
                return false;
            }
            if ($('#detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('见面地点纬度获取失败');
                return false;
            }
            if ($('#detail-end-place').val() == null || $('#detail-end-place').val() == '') {
                showMessage('请选择目的地:');
                return false;
            }
            if ($('#detail-end-longitude').val() == null || $('#detail-end-longitude').val() == '') {
                showMessage('目的地经度获取失败');
                return false;
            }
            if ($('#detail-end-latitude').val() == null || $('#detail-end-latitude').val() == '') {
                showMessage('目的地纬度获取失败');
                return false;
            }
            break;
        case 'hw'://其他
            if ($('#detail-start-place').val() == null || $('#detail-start-place').val() == '') {
                showMessage('请选择服务地点:');
                return false;
            }
            if ($('#detail-start-longitude').val() == null || $('#detail-start-longitude').val() == '') {
                showMessage('服务地点经度获取失败');
                return false;
            }
            if ($('detail-start-latitude').val() == null || $('#detail-start-latitude').val() == '') {
                showMessage('服务地点纬度获取失败');
                return false;
            }
            break;
    }
	if ($('#detail-username').val() == null || $('#detail-username').val() == '') {
		showMessage('请输入联系人');
            return false;
    }
    if ($('#detail-phone').val() == null || $('#detail-phone').val() == '') {
        showMessage('请输入联系电话');
			return false;
    }
    if(!/^1[34578]\d{9}$/.test($('#detail-phone').val())) {
        showMessage('请输入正确的手机号码');
        return false;
    }
    return true;
}





